#!/bin/bash
# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: jaewon

set -e

WORKING_DIR="/remote/iosg/home/jaewon/ops/bitmex/"

export TZ="UTC"
YESTERDAY=$(date -u -d 'yesterday' '+%Y%m%d')
DEST_DIR="/remote/iosg/home/jaewon/data/flow/feed-01.eu-west-1.aws/${YESTERDAY}/"
mkdir -p "${DEST_DIR}"

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
cd "${WORKING_DIR}"

echo "$(date '+%Y-%m-%d %H:%M:%S')] Start pulling feed"
echo "$(date '+%Y-%m-%d %H:%M:%S')] Downloading ${YESTERDAY}/okex_ws_futureusd_*"
"${SCRIPT_DIR}/remotecopy" \
  --append-verify \
  --no-compression \
  --bwlimit 4096 \
  --batch-mode \
  --quiet \
  -F ssh_config/ssh_config \
  -i ssh_config/aws-ec2-coin-key-eu-west-1.pem \
  "ec2-user@feed-01.eu-west-1.aws:data/flow/feed-01.eu-west-1.aws/${YESTERDAY}/okex_ws_futureusd_*" \
  "${DEST_DIR}"

echo "$(date '+%Y-%m-%d %H:%M:%S')] Downloading ${YESTERDAY}/bitmex_*"
"${SCRIPT_DIR}/remotecopy" \
  --append-verify \
  --no-compression \
  --bwlimit 4096 \
  --batch-mode \
  --quiet \
  -F ssh_config/ssh_config \
  -i ssh_config/aws-ec2-coin-key-eu-west-1.pem \
  "ec2-user@feed-01.eu-west-1.aws:data/flow/feed-01.eu-west-1.aws/${YESTERDAY}/bitmex_*" \
  "${DEST_DIR}"

echo "$(date '+%Y-%m-%d %H:%M:%S')] Done"
